<?php

/**
 * QCMS
 *
 * Copyright (c) 2022 QCMS
 *
 * @author lbnnbs
 * @copyright Copyright (c) 2022 lbnnbs QCMS (https://gitee.com/lbnnbs/qcms)
 * @license AGPLv3 License
 *
 * 带状态字段的表模型
 *
 * @property array $_states 可用状态的关联数组，使用类必须声明该属性
 */
trait State {
    
    /**
     * @param $key
     * @return mixed|string|string[]
     */
    public function getStateAssoc($key = null) {
        
        if ($key !== null) {
            if (array_key_exists($key, $this->_states)) {
                return $this->_states[$key];
            }
            if (array_key_exists(strval($key), $this->_states)) {
                return $this->_states[strval($key)];
            }
            return '';
        } else {
            return $this->_states;
        }
        
    }
}